using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System;
using Microsoft.Xna.Framework.Content;

namespace OrtzEng.Graphics
{
    public class Sprite
    {
        #region Properties

        protected Vector2 _position;
        private Color _color;

        public virtual Vector2 Position
        {
            get { return _position; }

            set { _position = value; }
        }

        public float Width
        {
            get { return Size.X; }
            set { _size.X = value; }
        }
        public float Height
        {
            get { return Size.Y; }
            set { _size.Y = value; }
        }
        public int X
        {
            get { return Convert.ToInt32(_position.X); }
            set { _position.X = Convert.ToSingle(value); }
        }
        public int Y
        {
            get { return Convert.ToInt32(_position.Y); }
            set { _position.Y = Convert.ToSingle(value); }
        }
        public byte Alpha
        {
            get { return _color.A; }
            set { _color = new Color(_color.R, _color.G, _color.B, value); }
        }

        #endregion

        #region Field (spriteBatch, texture, position, source, color, rotation, origin, scale, effects, layer)

        public Rectangle Bounds
        {
            get { return new Rectangle((int)Position.X, (int)Position.Y, (int)Width, (int)Height); }
        }

        protected string _texturePath;

        protected Texture2D _texture;
        public Texture2D Texture
        {
            get { return _texture; }
            set { _texture = value; }
        }

        private Vector2 _size;
        public Vector2 Size
        {
            get { return _size; }
            set
            {
                _size = value;
            }
        }

        protected Color mColor;

        public Vector2 Scale
        {
            get { return new Vector2(_texture.Width / _size.X, _texture.Height / _size.Y); }
        }
        public virtual void Move(Vector2 position)
        {
            this._position = position;
        }
        public virtual void Bump(Vector2 increment)
        {
            this._position += increment;
        }

        #endregion

        #region Main Methods (LoadGraphicsContent, Initialize, Draw)

        public Sprite(string texturePath)
        {
            _texturePath = texturePath;
        }

        public Sprite(string texture, Vector2 position)
        {
            this._position = position;
        }

        public void LoadGraphicsContent(ContentManager content)
        {
            this.Texture = content.Load<Texture2D>(_texturePath);
        }

        public void Initialize()
        {
            this._color = Color.White;
        }

        public void Draw(SpriteBatch sBatch)
        {
            sBatch.Draw(this.Texture, this.Bounds, null, _color, 0f, new Vector2(0), SpriteEffects.None, 0.5f);
        }

        #endregion
    }
}
